import { ShaderMaterial, Texture } from "three";
import { ShaderPass } from "three/examples/jsm/postprocessing/ShaderPass.js";

export class MixPass extends ShaderPass {
  constructor({ texture }: { texture: Texture }) {
    super(
      new ShaderMaterial({
        uniforms: {
          baseTexture: { value: null },
          mixTexture: { value: texture },
        },
        vertexShader: `
              varying vec2 vUv;
    
              void main() {
                vUv = uv;
                gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
              }
            `,
        fragmentShader: `
              uniform sampler2D baseTexture;
              uniform sampler2D mixTexture;
    
              varying vec2 vUv;
    
              void main() {
                vec3 mixTextureColor = texture2D( mixTexture, vUv ).rgb;
                // gl_FragColor = texture2D( baseTexture, vUv ) * mixTextureColor.r;
                gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( mixTexture, vUv ) );
                // gl_FragColor = texture2D( mixTexture, vUv );
                // gl_FragColor = texture2D( baseTexture, vUv );
              }
            `,
      }),
      "baseTexture"
    );
  }
}
